package com.echo.echovividlive.config;

import com.echo.echovividlive.interceptor.WebSocketInterceptor;
import com.echo.echovividlive.websocket.ChatRoom;
import com.echo.echovividlive.websocket.LivingRoom;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.socket.config.annotation.WebSocketConfigurer;
import org.springframework.web.socket.config.annotation.WebSocketHandlerRegistry;
import org.springframework.web.socket.server.standard.ServerEndpointExporter;

@Slf4j
@Configuration
public class WebSocketConfig implements WebSocketConfigurer {

    @Resource
    private LivingRoom livingRoom;

    @Bean
    public ServerEndpointExporter serverEndpointExporter(){
        return new ServerEndpointExporter();
    }

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry.addHandler(new ChatRoom(),"/chat")
                .addHandler(livingRoom,"/live/**")
                .setAllowedOrigins("*")
                .addInterceptors(new WebSocketInterceptor());
    }
}
